# Monarc makefile

CC  = gcc
AS  = nasm
LD  = ld
AR  = ar
SED = sed
PL = perl

ifndef BASE
	BASE = ../..
endif

INCL = \
	-I$(BASE)/include \
	-I$(BASE)/klibc/include \

MODULES_PATH = $(BASE)/modules

LIBC_PATH = $(BASE)/klibc
LIB_PATH = \
	-L$(LIBC_PATH) \
		
LIBS = \
	-lklibc \

LIB_DEPS = \

DEFINES = \
#	-D__DEBUG \

OPT_OR_DEBUG = \
	-O1 -fno-rtti -fno-exceptions

OC_OPT = \
	-Wall \
	$(OPT_OR_DEBUG) \
	-mno-stack-arg-probe \
	-ffreestanding \
	-nostartfiles \
	-nodefaultlibs \
	-nostdlib \
	-nostdinc \
	$(INCL) \
	$(DEFINES)
	
OCC_OPT = \
	-Wall \
	$(OPT_OR_DEBUG) \
	-mno-stack-arg-probe \
	-nostartfiles \
	-fno-builtin \
	-nodefaultlibs \
	-nostdlib \
	-nostdinc \
	$(INCL) \
	$(DEFINES)

MKDIR = mkdir
CP = cp
CAT = cat
RM = rm -f

MODULE_MODULES = \
	main.cc \

all: module.o

clean:
	$(RM) *.o
	
module.o : $(MODULE_MODULES:.cc=.o)
	$(LD) -Ur $(MODULE_MODULES:.cc=.o) -o module.o -Map module.map -T $(MODULES_PATH)/module.ld
	objdump -t module.o | perl $(MODULES_PATH)/symbols.pl > module.sym
	$(MODULES_PATH)/bin2c module.o

%.o : %.asm
	$(AS) -O99 -fwin32 $< -o $@

%.o: %.c %.h
	$(CC) $(OC_OPT) -c $< -o $@

%.o: %.cc %.h
	$(CC) $(OCC_OPT) -c $< -o $@

%.o: %.cc
	$(CC) $(OCC_OPT) -c $< -o $@

